#!/usr/bin/env ruby
require 'yaml'

 class BaseClass

   def doCacheByYamlToPath(cacheDirPath,fileName)
     puts "....do cache to #{cacheDirPath}"
     unless File::exists?(cacheDirPath)
       Dir.mkdir(cacheDirPath,0777)
     end
     File.open( cacheDirPath + fileName + '.yaml', "w") { |file| YAML.dump(self, file) }
   end

   def self.loadFromCacheByPath(cachePath)
     filePath = cachePath + "/#{fileName}" + '.yaml'
     if File::exist?(filePath)
       cfc = YAML::load( File.open(filePath) )
       puts self.to_s + '缓存存在'
     else
       puts self.to_s + '缓存不存在'
     end
     return cfc
   end

 end
